<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Helper file: util_helper
 *
 * @author luubk
 * @since 10-06-2012 - 02:22:51
 */
if (!function_exists('_jsonout')) :

    function _jsonout($bool, $message = '', $data = false)
    {
        if ($bool) $bool = true;
        else $bool = false;

        $ar_out = array('success' => $bool);
        if (!empty($message)) $ar_out['message'] = $message;
        if ($data !== false) $ar_out['data'] = $data;

        header("Content-Type: application/json");
        echo json_encode($ar_out);
        exit();
    }

endif;


if (!function_exists('_typeadhead_jsonout')) :

    function _typeadhead_jsonout($data = array())
    {
        header("Content-Type: application/json");
        echo json_encode($data);
        exit();
    }

endif;

if (!function_exists('encrypt_pass')) :

    function encrypt_pass($pass)
    {
        return md5(md5($pass . SITE_TITLE) . PASS_SALT);
    }

endif;

if (!function_exists('status_text')) :

    function status_text($status)
    {
        return ($status == 1) ? 'Kích hoạt' : 'Vô hiệu hóa';
    }

endif;

if (!function_exists('edit_text')) :

    function edit_text($url)
    {
        $txt = '<a href="' . site_url($url);
        $txt .= '"><input type="image" src="' . base_url() . 'assets/template/default/images/icn_edit.png" title="Sửa"></a>';
        return $txt;
    }

endif;

if (!function_exists('delete_text')) :

    function delete_text($url)
    {
        $txt = '<a href="' . site_url($url) . '" ';
        $txt .= 'onclick="return confirm(\'Bạn có chắc là muốn xóa phần tử này không?\')"';
        $txt .= '><input type="image" src="' . base_url() . 'assets/template/default/images/icn_trash.png" title="Xóa"></a>';
        return $txt;
    }

endif;

if (!function_exists('nice_url')) :

    function nice_url($url)
    {
        while (strpos($url, '//') !== FALSE)
        {
            $url = str_replace('//', '/', $url);
        }        
        return $url;
    }

endif;
?>
